﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using Northwind.NET.Model;
using System.Runtime.Serialization;
using System.IO;
using System.Diagnostics;

namespace NorthwindTests
{
	public static class NorthwindTestHelper
	{
		public static bool CanSerializeDeserialize<T>(T objectgraph)
		{

			DataContractSerializer serializer = new DataContractSerializer(typeof(T), KnownTypesNET);
			using (MemoryStream mem1 = new MemoryStream())
			{
				try
				{
					serializer.WriteObject(mem1, objectgraph);
					mem1.Position = 0;
					T read = (T)serializer.ReadObject(mem1);
					return true;
				}
				catch (StackOverflowException ex)
				{
					Debug.WriteLine(ex);
					return false;
				}
				catch (Exception ex)
				{
					Debug.WriteLine(ex);
					return false;
				}
				
			}
		}

		public static IEnumerable<Type> KnownTypesNET = new Type[] 
			{ 
				typeof(SequencedObject), 
				typeof(Customer), 
				typeof(Supplier), 
				typeof(Product),				
				typeof(Shipper),
				//typeof(IDataPointKey), 
				//typeof(ISequencedObjectKey),				
				//typeof(SecurityInfo), 
			};

		public static DbConnection dbconnection =
			new System.Data.SqlClient.SqlConnection("server=.;database=northwind;integrated security=true;");
	}
}
